// Haxzs Audio Server
// made by omghaxzs
// 2010

#include "log.h"

logwnd::logwnd(int y, int x, int width, int height):window(y, x, width, height)
{
	cursory = 1;
	maxlines = height-2;
	// Initialize curses screen
	if(has_colors() == FALSE)
	{	
		endwin();
		printf("Your terminal does not support color\n");
		exit(1);
	}

	// Create a new window
	win = newwin(height, width, y, x);

	scrollok(win, true);
	box(win, 0, 0);

	wrefresh(win);

	// Initially set the cursor
	wmove(win, 1, 1);
}

logwnd::~logwnd()
{
	endwin();
}

void logwnd::printMsg(std::string str, bool newline)
{
	wprintw(win, str.c_str());
	wrefresh(win);
	if (newline)
	{
		if (cursory != maxlines)
		{
			cursory++;
			wmove(win, cursory, 1);
		}
		else
		{
			wmove(win, cursory, 1);
			
			// Scroll up
			wscrl(win, 1);

			// Delete the last line
			wdeleteln(win);

			// Redraw the box
			box(win, 0, 0);
		}
	}
}